<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>创建关联的产品需求</title>
    <link href="../css/common.css" type="text/css" rel="stylesheet"/>
</head>
<body>


<!--header-->
<header id="header" class="header">
    <div class="header-info left"><i></i><a href="pm-need-list.html">需求列表</a> > 创建相关需求</div>
    <div class="right-user right">
         <div class="clear t" >             <div id="headusername" class="role"></div>             <div class="icon"></div>         </div>
        <div class="head-down">
            <ul><li><a href="edit-pwd.html">修改密码</a></li><li><a onclick="loginOut()">退出系统</a></li></ul></div><div>
    </div>
    </div>
</header>
<!--menu-->
<aside id="aside" class="aside">
    <div class="logo">运营平台</div>
    <ul class="menu" id="asidemenu">
    </ul>
</aside>

<!--content-->
<div class="content">
    <div class="page-inner">
        <div class="page-content">
            <div class="table-head"><i></i>产品需求</div>
            <div class="table-cont">
                <table class="content-table">
                    <tr>
                        <td>相关原始需求：</td>
                        <td id="relativeNeed"></td>
                    </tr>
                    <tr>
                        <td><span class="red-start">*</span>需求名称：</td>
                        <td><input type="text" id="name" placeholder="不超过15个字符" /><i class="error-icon"></i></td>

                    </tr>
                    <tr>
                        <td><span class="red-start">*</span>类别：</td>
                        <td><select id="typeList"></select></td>
                        <td><span class="red-start">*</span>产品：</td>
                        <td><select id="productList" onchange="_API.getFunctionList('functionList',false,false,'productList')"></select></td>
                    </tr>
                    <tr>
                        <td><span class="red-start">*</span>使用平台：</td>
                        <td><select id="platformList"></select></td>
                        <td><span class="red-start">*</span>功能模块：</td>
                        <td><select id="functionList"><option>请选择</option></select><span style="color:#4cae4c;">先选择产品</span></td>
                    </tr>
                    <tr>
                        <td>优先级别：</td>
                        <td><select id="priority"></select></td>
                        <td>计划版本：</td>
                        <td><input type="text" id="version" placeholder="如：1.0版本"/></td>
                    </tr>
                    <tr>

                        <td>处理状态：</td>
                        <td><select id="status"></select></td>
                    </tr>
                    <tr class="area">
                        <td>简述：</td>
                        <td colspan="3">
                            <textarea id="discribe"></textarea>
                        </td>
                    </tr>
                    <tr class="area">
                        <td>方案思路：</td>
                        <td colspan="3">
                            <textarea id="solution"></textarea>
                        </td>
                    </tr>
                    <tr class="area">
                        <td>附件：</td>
                        <td colspan="3">
                            <a href="javascript:;" class="a-upload" id="fileUpload"><input id="file" value="请选择" type="file"/>点击这里上传</a>
                            <p class="format">支持的格式有：JPG，PNG，PDF，PPT，XLSX，XLS，CSV，DOCX，DOC，ZIP</p>
                            <p class="format">文件名不能包含*、#等特殊符号</p>
                            <ul class="addAttachmentList" id="addAttachmentList">
                            </ul>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="buttons">
                <a class="cancel" onclick="returnLink()">取消</a>
                <a onclick="commit(this)">提交</a>
            </div>
        </div>
    </div>
</div>
<script src="../js/jquery.min.js"></script>
<script src="../js/jquery.cookie.js"></script>
<script src="../js/common.js"></script>

<script type="text/javascript">
    _API.getTypeList('typeList')
        .getProductList('productList')
        .getPlatformList('platformList')
        .getFunctionList('functionList',false,false,false,'MDISP')
        .getPriorityList('priority')
        .getStatusListPm('status');


    var _id = getUrlId();
    function returnLink(){
        location.href = 'pm-need-detail-mems.html?id='+_id;
    }
    relativeNeed();
    function relativeNeed(){
        h = '<a class="r-name">'+decodeURI($$.getUrlParaObj()['name'])+'</a>';
        $('#relativeNeed').html(h);
    }

     // 上传文件
    var attachment = new attachment();
    attachment.init({
        fileUpload:$('#fileUpload'),
        addAttachmentList:$('#addAttachmentList')
    }).deleteFile();



    var named = $('#name');
//        version = $('#version');
    named.focus(function(){
        named.removeClass('error-i');
        named.siblings('.error-icon').css({'visibility':'hidden'});
    })


    var isClick = false;
    function commit(that) {
        if(named.val() == ''){
            named.addClass('error-i');
            named.siblings('.error-icon').css({'visibility':'visible'});
            return
        } 
//        if( version.val() == ''){
//            version.addClass('error-i');
//            version.siblings('.error-icon').css({'visibility':'visible'});
//            return;
//        }

        var attachment = [];
        var li = $('#addAttachmentList').find('li');
        if(li.length >= 1){
            li.each(function(){
                attachment.push( $(this).attr('rel') );
            })
        }

        var url  = _ip+'/product/addRequire';
        var data = {
                "oid":_id,
                "creater":$.cookie('username'),
                "feature":$('#functionList').val(),
                "name":$('#name').val(),
                "plat":$('#platformList').val(),
                "product":$('#productList').val(),
                "type":$('#typeList').val(),
                "attachment":attachment.join(','),
                "priority":$('#priority').val(),
                "status":$('#status').val(),
                "version":$('#version').val(),
                "solution":$('#solution').val(),
                "discribe":$('#discribe').val()
                
            }

        if(isClick) return;
        $(that).addClass('sending');
        isClick = true;
        $.ajax({
            url:url,
            type: 'post',
            xhrFields: {
                withCredentials: true
            },
            crossDomain: true,
            dataType: 'json',
            contentType:'application/json',
            data:JSON.stringify(data),
            success:function(data){
                if(data.success){
                    location.href = 'pm-need-detail-mems.html?id='+_id;
                }else{
                    alert('关联失败, 请稍后重试！');
                }
            }
        })
   }
</script>
</body>
</html>